package com.clive.xxweb.service.impl;

import com.clive.xxweb.bean.DishCategory;
import com.clive.xxweb.exception.GlobalException;
import com.clive.xxweb.mapper.DishCategoryMapper;
import com.clive.xxweb.mapper.DishMapper;
import com.clive.xxweb.service.DishCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.security.GeneralSecurityException;
import java.util.List;
@Service
public class DishCategoryServiceImpl implements DishCategoryService {
    @Autowired
    private DishCategoryMapper dishcategoryMapper;
    @Autowired
    private DishMapper dishMapper;
//    事务管理   事务回滚
    @Transactional
    @Override
    public List<DishCategory> findDishCategoryAll() {
        List<DishCategory> list = dishcategoryMapper.findDishCategoryAll();
        return list;
    }

    @Override
    public int deleteDishCategoryById(Integer id) {
        int i = dishMapper.delteDishCategoryById(id);
        int j = dishcategoryMapper.deleteCategory(id);
        if (j<=0){
            throw new GlobalException("删除菜品失败");
        }
        return j;
    }
}
